home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / PIELOGO.ARJ / EGAGRAF.ASM < prev    next >
Assembly Source File  |  1992-02-02  |  5KB  |  293 lines

  1. ; egagraf.asm     Copyright (c) 1992 Kevin Stokes, Pie in the Sky Software
  2. ;
  3. ; The line drawing routine used here was lifted from Richard Wilton's book
  4. ; Programmer's Guide to PC & PS/2 Video Systems  1987 Microsoft Press
  5. ;
  6.     title 'egagraf'
  7.  
  8.                 ; this subroutine plots a line on an ega
  9.                 ; screen
  10.                 ; This code is lifted from the book
  11.                 ; 'Programmer's guide to PC, and PS/2
  12.                 ; Video systems by Richard Wilton
  13. include c:\powerc\pcmac.asm
  14. modbeg egagraf
  15. include 3dvid.inc
  16. include pixaddr1.inc
  17.  
  18.  
  19.  
  20.  
  21. ;         mov    register,word ptr [bp+(number*2+4)]
  22. ;.dataseg
  23. ;vertincr    dw    0
  24. ;incr1        dw    0
  25. ;incr2        dw    0
  26. ;routine        dw    0
  27. ;rflag        db    0
  28. ;argx2        dw    0
  29. ;argx1        dw    0
  30. ;argy1        dw    0
  31. ;argy2        dw    0
  32. ;n        db    15
  33. ;vboff        dw    0
  34. ;.ends
  35. argx1    equ    [bp+(1*2+4)]
  36. argy1    equ    [bp+(2*2+4)]
  37. argx2    equ    [bp+(3*2+4)]
  38. argy2    equ    [bp+(4*2+4)]
  39. n    equ    [bp+(5*2+4)]
  40. vertincr    equ    [bp-6]
  41. incr1        equ    [bp-8]
  42. incr2        equ    [bp-10]
  43. routine        equ    [bp-12]
  44.  
  45. pixeladdr10    proc    near
  46. ;    mov    dx,ax        ; multiply y by 80
  47. ;    shl    ax,1        ; mult by 4
  48. ;    shl    ax,1        ; mult by 4
  49. ;    add    ax,dx        ; not it's by 5
  50. ;    mov    cl,4        ; now by 16
  51. ;    shl    ax,cl
  52.     push    dx
  53.     mov    dx,bpl        ; bytes per line
  54.     mul    dx
  55.     mov    cl,3
  56.     mov    dx,bx        ; save old x low part
  57.     shr    bx,cl
  58. ;    add    bx,vboff    ; add in offset
  59.     add    bx,ax        ; add in y offset
  60.     mov    cx,dx
  61.     and    cl,7
  62.     xor    cl,7
  63.     mov    ax,vgseg    ; load es with proper segment
  64.     mov    es,ax
  65.     mov    ah,1
  66.     pop    dx
  67.     ret
  68. pixeladdr10    endp
  69.  
  70. procbeg    egaline
  71.     sub    sp,14        ; make a clear stack frame for temp vars
  72.     mov    dx,3ceh        ; dx := graphics controller port addr
  73.     mov    ah,n
  74.     xor    al,al
  75.     out    dx,ax
  76.     mov    ax,0f01h
  77. ;    mov    rflag,ah
  78.     out    dx,ax
  79.     mov    ah,0
  80.     mov    al,3
  81.     out    dx,ax
  82. regal:    mov    si,bpl        ; number of bytes per line
  83.     mov    cx,argx2
  84.     sub    cx,argx1
  85.     jnz    fyou
  86.     jmp    vertline10    ; do vertical line if delta-x is zero
  87. ; force x1<x2
  88. fyou:    jns    l01
  89.     neg    cx
  90.     mov    bx,argx2
  91.     xchg    bx,argx1
  92.     mov    argx2,bx
  93.     mov    bx,argy2
  94.     xchg    bx,argy1
  95.     mov    argy2,bx
  96. ; calculate dy = abs(y2-y1)
  97. l01:    mov    bx,argy2
  98.     sub    bx,argy1
  99.     jnz    fyou2
  100.     jmp    horizline10
  101. fyou2:    jns    l03
  102.     neg    bx
  103.     neg    si
  104. ;select appropriate routine for slope of line
  105. l03:    mov    vertincr,si
  106.     mov    routine,offset loslopeline
  107.     cmp    bx,cx
  108.     jle    l04
  109.     mov    routine,offset hislopeline
  110.     xchg    bx,cx            ; exchange dy and dx
  111. ; calculate initial decision variable and increments
  112. l04:    shl    bx,1
  113.     mov    incr1,bx
  114.     sub    bx,cx
  115.     mov    si,bx
  116.     sub    bx,cx
  117.     mov    incr2,bx
  118. ; calculate first pixel address
  119.     push    cx
  120.     mov    ax,argy1
  121.     mov    bx,argx1
  122. ;    call    pixeladdr10
  123.     pixadd
  124.     mov    di,bx
  125.     shl    ah,cl
  126.     mov    bl,ah
  127.     mov    al,8
  128.     pop    cx
  129.     inc    cx
  130. ;    jmp    lexit
  131.     jmp    routine
  132. ; routine for verical lines
  133. vertline10:    mov    ax,argy1
  134.     mov    bx,argy2
  135.     mov    cx,bx
  136.     sub    cx,ax
  137.     jge    l31
  138.     neg    cx
  139.     mov    ax,bx
  140. l31:    inc    cx
  141.     mov    bx,argx1
  142.     push    cx
  143.     call    pixeladdr10
  144. ;    pixadd
  145. ; set up graphics controller
  146.     shl    ah,cl
  147.     mov    al,8
  148.     out    dx,ax
  149.     pop    cx
  150. ; draw the line
  151. l32:    or     es:[bx],al    ;set pixel
  152.     add    bx,si        ; incr to next line
  153.     loop    l32
  154.     jmp    lexit
  155.  
  156. ; routine for horizontal lines
  157. horizline10:
  158.     push    ds
  159.     mov    ax,argy1
  160.     mov    bx,argx1
  161.     call    pixeladdr10
  162. ;    pixadd
  163.     mov    di,bx
  164.     mov    dh,ah
  165.     not    dh
  166.     shl    dh,cl
  167.     not    dh
  168.     mov    cx,argx2
  169.     and    cl,7
  170.     xor    cl,7
  171.     mov    dl,0ffh
  172.     shl    dl,cl
  173.     mov    ax,argx2
  174.     mov    bx,argx1
  175.     mov    cl,boffs
  176.     shr    ax,cl
  177.     shr    bx,cl
  178.     mov    cx,ax
  179.     sub    cx,bx
  180. ; get graphics controller port address into dx
  181.     mov    bx,dx
  182.     mov    dx,3ceh
  183.     mov    al,8
  184. ; make video buffer addressable through ds:si
  185.     push    es
  186.     pop    ds
  187.     mov    si,di
  188. ; set pixels in leftmost byte of the line
  189.     or    bh,bh
  190.     js    l43
  191.     or     cx,cx
  192.     jnz    l42
  193.     and    bl,bh
  194.     jmp    short l44
  195. l42:    mov    ah,bh
  196.     out    dx,ax
  197.     movsb    
  198.     dec    cx
  199. ; use a fast 8086 machine intruction to draw the remainder of the line
  200. l43:    mov    ah,-1
  201.     out    dx,ax
  202.     rep    movsb
  203. ; set pixels in the rightmost byte of the line
  204. l44:    mov    ah,bl
  205.     out    dx,ax
  206.     movsb
  207.     pop    ds
  208.     jmp    short lexit
  209. ; routine for dy >= dx        ; es:di -> video buffer
  210.                 ; al = bit mask register #
  211.                 ; bl = bit mask for 1st pixel
  212.                 ; cx = #pixels to draw
  213.                 ; dx = graphics controller port addr
  214.                 ; si = decision variable
  215. loslopeline:
  216. l10:    mov    ah,bl        ; 
  217. l11:    or    ah,bl
  218.     ror    bl,1
  219.     jc    l14
  220. ; bit mask not shifted out
  221.     or    si,si
  222.     jns    l12
  223.     add    si,incr1
  224.     loop    l11
  225.     out    dx,ax
  226.     or    es:[di],al
  227.     jmp    short lexit
  228. l12:    add    si,incr2
  229.     out    dx,ax
  230.     or    es:[di],al
  231.     add    di,vertincr
  232.     loop    l10
  233.     jmp    short    lexit
  234. ; bit mask shifted out
  235. l14:    out    dx,ax
  236.     or    es:[di],al
  237.     inc    di
  238.     or    si,si
  239.     jns    l15
  240.     add    si,incr1
  241.     loop    l10
  242.     jmp    short lexit
  243. l15:    add    si,incr2
  244.     add    di,vertincr
  245.     loop    l10
  246.     jmp    short lexit
  247. ; routine for dy > dx
  248. hislopeline:
  249.     mov    bx,vertincr
  250. l21:    out    dx,ax
  251. l21a:    or    es:[di],al
  252.     add    di,bx
  253. l22:    or    si,si
  254.     jns    l23
  255.     add    si,incr1
  256.     loop    l21a
  257.     jmp    short lexit
  258. l23:    add    si,incr2
  259.     ror    ah,1
  260.     adc    di,0
  261.     loop    l21
  262. ; restore default graphics controller state and return to caller
  263. lexit:
  264.     xor    ax,ax
  265. ;    cmp    al,rflag
  266. ;    mov    rflag,al
  267. ;    jnz    dorky
  268. ;    ret
  269. ;dorky:
  270.     out    dx,ax
  271.     inc    ax
  272.     out    dx,ax
  273.     mov    al,3
  274.     out    dx,ax
  275.     mov    ax,0ff08h
  276.     out    dx,ax
  277.     mov    sp,bp            ; restore stack stuff
  278. procend    egaline
  279.  
  280. procbeg    grmode
  281.     mov    ax,12h        ; use mode 10h
  282.     int    10h
  283. procend    grmode
  284.  
  285. procbeg    txmode
  286.     mov    ax,3h        ; use mode 10h
  287.     int    10h
  288. procend    txmode
  289.  
  290. modend egagraf
  291.  
  292.  
  293.